package com.lzq.leetcode.lanqiao.th12;

import java.util.Scanner;

public class s5 {

    public static long[] arr;

    public static int Max = 1414215;
    static {
        arr = new long[Max];

        arr[0] = 0;
        for (int i=1; i<Max; i++) {
            arr[i] = arr[i-1] + i;
        }
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int T = scan.nextInt();
        for (int i=0; i<T; i++) {

            int l = scan.nextInt();
            int r = scan.nextInt();
            int lp =1;
            int rp = 1;
            // 找到目标区间
            while (arr[lp] < l) lp++;
            while (arr[rp] < r) rp++;
            // 求和
            long sum = 0;
            // 求l侧的差值
            long indexP = arr[lp-1] + 1;
            for (int j=1; j<=lp; j++) {
                if (indexP >= l) {
                    sum += j;
                }
                indexP++;
            }
            // 求中间
            for (int j=lp+1; j<rp; j++) {
                sum += arr[j];
            }
            // 求末尾
            if (lp != rp) {
                indexP = arr[rp-1] +1;
                int counter = 1;
                for (long j=indexP; j<=r; j++) {
                    sum += counter++;
                }
            }

            System.out.println(sum);
        }
        //
        scan.close();
    }
}
